<html>
    <head>
        <title>如何使用编译服务类</title>
    </head>
    <body>
        <script>
            /*
                    三、如何使用编译服务类：

                               using System.Threading.Tasks;
                               using Volo.Abp.Application.Services; 

                               namespace YourNamespace
                               {
                                    public class CodeExecutionAppService: ApplicationService
                                    {
                                         private readonly DynamicCompilerService _compilerService;


                                         // 注入动态编译服务
                                         public CodeExecutionAppService(DynamicCompilerService compilerService)
                                         {
                                            _compilerService = compilerService;
                                         }

                                         public async Task<string> ExcuteCodeAsync(string code)
                                         {
                                            try
                                            {
                                                // 添加ABP相关引用
                                                _compilerService.AddReference(typeof(CurrentUser).Assembly);
                                                
                                                _compilerService.AddReference(typeof(Logger).Assembly);

                                                // 执行编译的代码
                                                var result = await _compilerService.CompileAndExecuteAsync(code);
                                                return result?.ToString()?? "执行成功，单没有返回值"；

                                            }
                                            catch(Exception ex)
                                            {
                                                return $"执行失败：{ex.Message}"
                                            }
                                         }
                                    }
                               }
                */
        </script>
    </body>
</html>